layui.use(['jquery', 'form', 'common', 'formSelects'], function() {
	var $ = layui.jquery;
	var form = layui.form;
	var common = layui.common;

	var changeType = function(value) {
		if (value == 1 || value == 2) {
			common.showItem('[name="url"]');
		} else {
			common.hideItem('[name="url"]');
		}
	};
	changeType($('[name="type"]').val());
	form.on('select(parentId)', function(data) {
		var value = data.value;
		if (value) {
			$('[name="type"] option[value="0"]').attr('disabled', true);
		} else {
			$('[name="type"] option[value="0"]').attr('disabled', false);
		}
		form.val('form', {
			'type': ''
		});
		form.render();
	});
	form.on('select(type)', function(data) {
		changeType(data.value);
	});
	form.on('submit(form)', function(data) {
		$.post('save', data.field, function(data) {
			if (data.state == 'ok') {
				// 成功，跳转到列表页面
				common.toUrl('list');
			} else {
				// 失败，弹出提示
				layer.msg(data.msg, {
					icon: 5,
					anim: 6
				});
			}
		});
		return false;
	});
});